package com.situ.company.init;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

/**
 * Servlet Filter implementation class UserFilter
 */
@WebFilter(urlPatterns = {"/web/page/*","/department","/employee"})
public class UserFilter implements Filter {

	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
		 HttpServletRequest req_ = (HttpServletRequest) req;
		 Object user = req_.getSession().getAttribute("user");
		 String action = req_.getParameter("action");
		 if("reg".equals(action)||"login".equals(action)) {
			 chain.doFilter(req, resp);
			 return;
		 }
		 if(user==null) {
			 req.getRequestDispatcher("/web/login.jsp").forward(req, resp);
		 }else
		chain.doFilter(req, resp);
	}

	
}
